﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;

namespace ITU.Yemekhane.App7
{


    public static class ResolutionChecker
    {
        public static bool IsRunningOnWP8
        {
            get
            {
                return Environment.OSVersion.Version.Major >= 8;
            }
        }

        static int _scaleFactor = -1;

        public static int ScaleFactor
        {
            get
            {
                if (_scaleFactor == -1)
                {

                    if (Environment.OSVersion.Version.Major < 8)
                    {
                        _scaleFactor = 100;
                    }
                    else
                    {
                        var scaleFactorProperty = Application.Current.Host.Content.GetType().GetProperty("ScaleFactor");
                        if (scaleFactorProperty != null)
                            _scaleFactor = (int)scaleFactorProperty.GetValue(Application.Current.Host.Content, null);
                    }
                }
                return _scaleFactor;
            }
        }
    }

    public enum Resolutions { WVGA, WXGA, HD720p };

    public static class ResolutionHelper
    {
        private static bool IsWvga
        {
            get
            {
                return ResolutionChecker.ScaleFactor == 100;
            }
        }

        private static bool IsWxga
        {
            get
            {
                return ResolutionChecker.ScaleFactor == 160;
            }
        }

        private static bool Is720p
        {
            get
            {
                return ResolutionChecker.ScaleFactor == 150;
            }
        }

        public static Resolutions CurrentResolution
        {
            get
            {
                if (IsWvga) return Resolutions.WVGA;
                else if (IsWxga) return Resolutions.WXGA;
                else if (Is720p) return Resolutions.HD720p;
                else throw new InvalidOperationException("Unknown resolution");
            }
        }
    }



    public class MultiResImageChooserUri
    {
        public Uri BestResolutionImageBackground
        {
            get
            {
                switch (ResolutionHelper.CurrentResolution)
                {
                    case Resolutions.HD720p:
                        return new Uri("panoramabg.screen-720p.png", UriKind.Relative);
                    case Resolutions.WXGA:
                        return new Uri("panoramabg.screen-wxga.png", UriKind.Relative);
                    case Resolutions.WVGA:
                        return new Uri("panoramabg.screen-wvga.png", UriKind.Relative);
                    default:
                        throw new InvalidOperationException("Unknown resolution type");
                }
            }
        }

    }
}
